package cn.bbs.ba.html;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import cn.bbs.ba.base.PPCodeDTO;
import cn.bbs.ba.path.BasePath;
import cn.com.zzz.tag.ResourceCenter;

public class ZPaiConstant {
	
	/** 当前国际化值zh_HK：繁体中文 en_US：英文 zh_ch:简体中文**/
	private static String strLanguage = "zh_ch";
	
	/**
	 * 资源中心，用于多语言显示
	 */
	protected static ResourceCenter RESOURCE_CENTER;
	
	private static String hot = "001";
	
	public static String getHot() {
		return hot;
	}

	public static void setHot(String hot) {
		ZPaiConstant.hot = hot;
	}

	/**
	 * 设定国际化当前参数
	 */
	public static void setLanguage(String pstr) {
		strLanguage = pstr;
	}
	
	/**
	 *  取得国际化当前参数
	 */
	public static String getLanguage() {
		return strLanguage;
	}
	
	
	public static void initAllPara() {
		// 加载资源文件 实现国际化
		RESOURCE_CENTER = new ResourceCenter(BasePath.getPath("resourcePath"));
	}
	
	/**
	 * 获取资源显示
	 * 
	 * @param resourceName
	 * @return String
	 */
	public static String disPlay( String resourceName)
	{
		String str = getResouceDisplayAt(resourceName);
		if (StringUtils.isEmpty(str)) {
			return resourceName;
		}
		return str;
	}
	
	/**
	 * 获取资源显示
	 * 
	 * @param resourceName
	 * @return String
	 */
	public String flexdisPlay( String resourceName)
	{
		String str = getResouceDisplayAt(resourceName);
		if (StringUtils.isEmpty(str)) {
			return resourceName;
		}
		return str;
	}
	
	/**
	 * 获取资源显示
	 * 
	 * @param resourceName
	 * @return String
	 */
	public static String getResouceDisplayAt( String resourceName)
	{
		String language = ZPaiConstant.getLanguage();
		if ( RESOURCE_CENTER != null )
		{
			return RESOURCE_CENTER.getResouceDisplayAt( resourceName, language );
		}
		else
		{
			return resourceName;
		}
	}
	
	/**
	 * 获取资源显示
	 * 
	 * @param resourceName
	 * @param language
	 * @return String
	 */
	public static String getResouceDisplayAt( String resourceName, String language )
	{
		if ( RESOURCE_CENTER != null )
		{
			return RESOURCE_CENTER.getResouceDisplayAt( resourceName, language );
		}
		else
		{
			return resourceName;
		}
	}
	
	/**
	 * 取得信息
	 */
	public static List<PPCodeDTO> getCodeData(String strCodeId) {
		List<PPCodeDTO> recodeList = new ArrayList<PPCodeDTO>();
		List<PPCodeDTO> codeList = ZPaiInit.getCodeMap().get(strCodeId);
		if (codeList == null) {
			return recodeList;
		}
		String strLang = ZPaiConstant.getLanguage();
		for (int i = 0; i < codeList.size(); i++)
		{	PPCodeDTO dto = codeList.get(i);
			if (!strLang.equals(dto.getLanguage())) {
				continue;
			}
			recodeList.add(dto);
		}
		return recodeList;
	}
	
	/**
	 * 取得信息
	 */
	public static String getCodeValue(String strCodeId, String systemCode) {
		
		List<PPCodeDTO> recodeList = getCodeData(strCodeId);
		
		for (int i = 0; i < recodeList.size(); i ++) {
			if (systemCode.equals(recodeList.get(i).getSystemId())) {
				return recodeList.get(i).getCvalue();
			}
		}
		return "";
	}
}
